package com.huawei.appmarket.service.productpurchase.card;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.CountDownTimer;
import android.text.SpannableString;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.horizontalcard.api.card.BaseHorizontalItemCard;
import com.huawei.appgallery.productpurchase.api.ProductDetailBean;
import com.huawei.appmarket.service.productpurchase.bean.HorizontalProductsInAppItemBean;
import com.huawei.appmarket.service.productpurchase.widget.CountDownLayout;
import huawei.widget.HwButton;
import java.lang.ref.WeakReference;
import o.azb;
import o.cgz;
import o.chc;
import o.chm;
import o.chy;
import o.cks;
import o.cku;
import o.crj;
import o.Logger;
import o.dof;
import o.ContentManager;
import o.eec;
import o.eed;
import o.epo;
import o.epw;
import o.eqx;
import o.evx;
import o.ewm.e;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;

public class HorizontalProductsInAppItemCard extends BaseHorizontalItemCard {
    private TextView ʻ;
    private TextView ʼ;
    private RelativeLayout ʽ;
    private HwButton ˊॱ;
    ProductDetailBean ˋ = new ProductDetailBean();
    private long ˋॱ;
    private CountDownLayout ˏॱ;
    private d ͺ;
    private ImageView ॱॱ;
    private TextView ᐝ;

    public class c implements crj {
        final /* synthetic */ HorizontalProductsInAppItemCard ॱ;

        public c(HorizontalProductsInAppItemCard horizontalProductsInAppItemCard) {
            this.ॱ = horizontalProductsInAppItemCard;
        }

        public void ˎ(int i, ProductDetailBean productDetailBean) {
            if (this.ॱ.ˊᐝ instanceof HorizontalProductsInAppItemBean) {
                HorizontalProductsInAppItemBean horizontalProductsInAppItemBean = (HorizontalProductsInAppItemBean) this.ॱ.ˊᐝ;
                switch (i) {
                    case 0:
                        if (((HorizontalProductsInAppItemBean) this.ॱ.ˊᐝ).ॱꜟ() == 1) {
                            horizontalProductsInAppItemBean.ˏॱ(2);
                            this.ॱ.ˊॱ.setEnabled(false);
                            this.ॱ.ˊॱ.setText(this.ॱ.ʼॱ.getResources().getString(n.ʼꜞ));
                            Toast.makeText(this.ॱ.ʼॱ, n.ʼꓸ, 0).show();
                            return;
                        }
                        return;
                    case 4:
                        horizontalProductsInAppItemBean.ʽ(0);
                        this.ॱ.ॱˊ();
                        return;
                    case 5:
                        Toast.makeText(this.ॱ.ʼॱ, n.ʼꞌ, 0).show();
                        return;
                    case 6:
                        this.ॱ.ˊॱ.setEnabled(false);
                        this.ॱ.ˊॱ.setText(this.ॱ.ʼॱ.getResources().getString(n.ʼꜞ));
                        Toast.makeText(this.ॱ.ʼॱ, n.ʼꜞ, 0).show();
                        return;
                    default:
                        Logger.ˎ("HorizontalProductsInAppItemCard", "Purchase failure");
                        return;
                }
            }
        }
    }

    public static class d extends CountDownTimer {
        private WeakReference<CountDownLayout> ˋ;
        private HorizontalProductsInAppItemBean ˎ;
        private WeakReference<HwButton> ˏ;
        private WeakReference<TextView> ॱ;

        public d(long j, long j2, CountDownLayout countDownLayout, TextView textView, HwButton hwButton, HorizontalProductsInAppItemBean horizontalProductsInAppItemBean) {
            super(j, j2);
            this.ˋ = new WeakReference(countDownLayout);
            this.ॱ = new WeakReference(textView);
            this.ˏ = new WeakReference(hwButton);
            this.ˎ = horizontalProductsInAppItemBean;
        }

        public void onTick(long j) {
            CountDownLayout countDownLayout = (CountDownLayout) this.ˋ.get();
            if (countDownLayout != null) {
                countDownLayout.setPromoteTime(j);
            }
        }

        public void onFinish() {
            CountDownLayout countDownLayout = (CountDownLayout) this.ˋ.get();
            TextView textView = (TextView) this.ॱ.get();
            HwButton hwButton = (HwButton) this.ˏ.get();
            if (countDownLayout != null) {
                countDownLayout.setVisibility(4);
            }
            if (textView != null) {
                textView.setVisibility(4);
            }
            if (hwButton != null) {
                hwButton.setText(eed.ˋ(this.ˎ.ʼᐝ(), this.ˎ.ʻᐝ()));
            }
        }
    }

    public cgz ˏ(View view) {
        super.ˏ(view);
        this.ʽ = (RelativeLayout) view.findViewById(j.ᶤ);
        this.ॱॱ = (ImageView) view.findViewById(j.ᶫᐝ);
        this.ʼ = (TextView) view.findViewById(j.ᶫˋ);
        this.ʻ = (TextView) view.findViewById(j.ᶫˊ);
        this.ᐝ = (TextView) view.findViewById(j.ᶦॱ);
        this.ˏॱ = (CountDownLayout) view.findViewById(j.ᵢˎ);
        this.ˊॱ = (HwButton) view.findViewById(j.ᵢᐝ);
        ʽ(view);
        if (view instanceof RelativeLayout) {
            this.ʽ = (RelativeLayout) view;
            LayoutParams layoutParams = this.ʽ.getLayoutParams();
            layoutParams.width = ((azb.ॱ(this.ʼॱ) - (ॱॱ() * 2)) - (ʼ() * (ʻ() - 1))) / ʻ();
            this.ʽ.setLayoutParams(layoutParams);
        }
        return this;
    }

    public int ˊ() {
        return h.ﹺ;
    }

    public int ˎ() {
        return h.ﹺ;
    }

    public void ˎ(BaseCardBean baseCardBean) {
        super.ˎ(baseCardBean);
        if (baseCardBean instanceof HorizontalProductsInAppItemBean) {
            HorizontalProductsInAppItemBean horizontalProductsInAppItemBean = (HorizontalProductsInAppItemBean) baseCardBean;
            eqx.ˏ(this.ॱॱ, horizontalProductsInAppItemBean.ʼˊ(), "image_default_icon");
            ˎ(this.ʼ, horizontalProductsInAppItemBean.ʻˋ());
            ˎ(this.ʻ, horizontalProductsInAppItemBean.ʻˊ());
            this.ˋॱ = horizontalProductsInAppItemBean.ʾॱ() - System.currentTimeMillis();
            this.ᐝ.setVisibility(4);
            this.ˏॱ.setVisibility(4);
            if (this.ͺ != null) {
                this.ͺ.cancel();
            }
            ˊ(horizontalProductsInAppItemBean);
            Drawable drawable = this.ʼॱ.getResources().getDrawable(e.ʾ);
            if (epw.ˏ()) {
                drawable = epo.ॱ(drawable, this.ʼॱ.getResources().getColor(o.ewm.c.ॱॱ));
            } else {
                drawable = epo.ॱ(drawable, this.ʼॱ.getResources().getColor(o.ewm.c.ˊᐝ));
            }
            this.ˊॱ.setBackground(drawable);
            ॱ((HorizontalProductsInAppItemBean) baseCardBean);
        }
    }

    public int ʻ() {
        return eed.ˋ(this.ʼॱ);
    }

    public int ॱॱ() {
        return chc.ˏ();
    }

    public int ʼ() {
        return chc.ˋ();
    }

    public HorizontalProductsInAppItemCard(Context context) {
        super(context);
    }

    public void ॱ(chy o_chy) {
        this.ˊॱ.setOnClickListener(new evx(this) {
            final /* synthetic */ HorizontalProductsInAppItemCard ˎ;

            {
                this.ˎ = r1;
            }

            public void ˋ(View view) {
                if (this.ˎ.ʼॱ instanceof Activity) {
                    eec.ˊ().ˎ((Activity) this.ˎ.ʼॱ, this.ˎ.ˋ, new c(this.ˎ));
                }
            }
        });
    }

    private void ॱ(HorizontalProductsInAppItemBean horizontalProductsInAppItemBean) {
        this.ˋ.ʾ(horizontalProductsInAppItemBean.ʼˊ());
        this.ˋ.ॱʼ(horizontalProductsInAppItemBean.ʻˋ());
        this.ˋ.ॱʻ(horizontalProductsInAppItemBean.ʻˊ());
        this.ˋ.ˈ(horizontalProductsInAppItemBean.ʻᐝ());
        this.ˋ.ʼॱ(horizontalProductsInAppItemBean.ʼˋ());
        this.ˋ.ˎˏ(horizontalProductsInAppItemBean.ʼᐝ());
        this.ˋ.ˑ(horizontalProductsInAppItemBean.ʽˊ());
        this.ˋ.ˎ(horizontalProductsInAppItemBean.ʾॱ());
        this.ˋ.ͺॱ(horizontalProductsInAppItemBean.ʽˋ());
        this.ˋ.ـ(horizontalProductsInAppItemBean.ʽᐝ());
        this.ˋ.ॱʽ(horizontalProductsInAppItemBean.ॱﾞ());
        this.ˋ.ᐝ(horizontalProductsInAppItemBean.ʿॱ());
        this.ˋ.ʽ(horizontalProductsInAppItemBean.ˊʻ());
        this.ˋ.ʼ(horizontalProductsInAppItemBean.ॱꞌ());
        this.ˋ.ˏॱ(horizontalProductsInAppItemBean.ॱꜟ());
        this.ˋ.ʻ(horizontalProductsInAppItemBean.ˌ());
        this.ˋ.ˉ(horizontalProductsInAppItemBean.ͺˏ());
        this.ˋ.ॱ(horizontalProductsInAppItemBean.י());
    }

    public void ˎ(TextView textView, String str) {
        if (dof.ˋ(str)) {
            textView.setVisibility(8);
            return;
        }
        textView.setVisibility(0);
        textView.setText(str);
    }

    private void ˎ(TextView textView, String str, String str2) {
        int i = (dof.ˋ(str2) || Double.valueOf(str2).doubleValue() > 0.0d) ? 0 : 1;
        if (dof.ˋ(str) || i != 0) {
            textView.setVisibility(4);
            return;
        }
        textView.setVisibility(0);
        CharSequence spannableString = new SpannableString(str);
        spannableString.setSpan(chm.ॱ, 0, spannableString.length(), 33);
        textView.setText(spannableString);
    }

    public void ˋ(HwButton hwButton, String str) {
        if (dof.ˋ(str)) {
            hwButton.setVisibility(8);
            return;
        }
        hwButton.setVisibility(0);
        hwButton.setText(str);
    }

    public void ˊ(HorizontalProductsInAppItemBean horizontalProductsInAppItemBean) {
        ˋ(horizontalProductsInAppItemBean);
        ˎ(horizontalProductsInAppItemBean);
    }

    private void ˋ(HorizontalProductsInAppItemBean horizontalProductsInAppItemBean) {
        if (horizontalProductsInAppItemBean.ˌ() != 0) {
            this.ˊॱ.setEnabled(false);
        } else {
            this.ˊॱ.setEnabled(true);
        }
    }

    private void ˎ(HorizontalProductsInAppItemBean horizontalProductsInAppItemBean) {
        if (horizontalProductsInAppItemBean.ॱꜟ() == 1) {
            ॱ(horizontalProductsInAppItemBean, true);
        } else if (horizontalProductsInAppItemBean.ॱꜟ() == 2) {
            this.ˊॱ.setText(this.ʼॱ.getResources().getString(n.ʼꜞ));
            this.ˊॱ.setEnabled(false);
            ˎ(this.ᐝ, eed.ˋ(horizontalProductsInAppItemBean.ʼᐝ(), horizontalProductsInAppItemBean.ʻᐝ()), horizontalProductsInAppItemBean.ʻᐝ());
        } else {
            ॱ(horizontalProductsInAppItemBean, false);
        }
    }

    private void ॱ(HorizontalProductsInAppItemBean horizontalProductsInAppItemBean, boolean z) {
        if (horizontalProductsInAppItemBean.ॱꞌ() <= 0 && horizontalProductsInAppItemBean.ॱꞌ() != -1) {
            this.ˊॱ.setEnabled(false);
            this.ˊॱ.setText(this.ʼॱ.getResources().getString(n.ʼᶥ));
            this.ᐝ.setVisibility(4);
        } else if (z) {
            ˏ(horizontalProductsInAppItemBean);
        } else {
            ᐝ(horizontalProductsInAppItemBean);
        }
    }

    private void ˏ(HorizontalProductsInAppItemBean horizontalProductsInAppItemBean) {
        if (horizontalProductsInAppItemBean.ʾॱ() <= 0) {
            this.ˊॱ.setText(this.ʼॱ.getResources().getString(n.ʼꜟ));
            ˎ(this.ᐝ, eed.ˋ(horizontalProductsInAppItemBean.ʼᐝ(), horizontalProductsInAppItemBean.ʻᐝ()), horizontalProductsInAppItemBean.ʻᐝ());
        } else if (this.ˋॱ > 0) {
            this.ˊॱ.setText(this.ʼॱ.getResources().getString(n.ʼꜟ));
            ˎ(this.ᐝ, eed.ˋ(horizontalProductsInAppItemBean.ʼᐝ(), horizontalProductsInAppItemBean.ʻᐝ()), horizontalProductsInAppItemBean.ʻᐝ());
            this.ˏॱ.setVisibility(0);
            this.ˏॱ.setPromoteTime(this.ˋॱ);
            ˏ(this.ˋॱ, horizontalProductsInAppItemBean);
        } else {
            ˋ(this.ˊॱ, eed.ˋ(horizontalProductsInAppItemBean.ʼᐝ(), horizontalProductsInAppItemBean.ʻᐝ()));
            this.ˏॱ.setVisibility(4);
        }
    }

    private void ᐝ(HorizontalProductsInAppItemBean horizontalProductsInAppItemBean) {
        if (dof.ˋ(horizontalProductsInAppItemBean.ʼˋ())) {
            ˋ(this.ˊॱ, eed.ˋ(horizontalProductsInAppItemBean.ʼᐝ(), horizontalProductsInAppItemBean.ʻᐝ()));
        } else if (horizontalProductsInAppItemBean.ʾॱ() <= 0) {
            ˎ(this.ᐝ, eed.ˋ(horizontalProductsInAppItemBean.ʼᐝ(), horizontalProductsInAppItemBean.ʻᐝ()), horizontalProductsInAppItemBean.ʻᐝ());
            ˋ(this.ˊॱ, eed.ˋ(horizontalProductsInAppItemBean.ʼᐝ(), horizontalProductsInAppItemBean.ʼˋ()));
        } else if (this.ˋॱ > 0) {
            ˎ(this.ᐝ, eed.ˋ(horizontalProductsInAppItemBean.ʼᐝ(), horizontalProductsInAppItemBean.ʻᐝ()), horizontalProductsInAppItemBean.ʻᐝ());
            ˋ(this.ˊॱ, eed.ˋ(horizontalProductsInAppItemBean.ʼᐝ(), horizontalProductsInAppItemBean.ʼˋ()));
            this.ˏॱ.setVisibility(0);
            this.ˏॱ.setPromoteTime(this.ˋॱ);
            ˏ(this.ˋॱ, horizontalProductsInAppItemBean);
        } else {
            ˋ(this.ˊॱ, eed.ˋ(horizontalProductsInAppItemBean.ʼᐝ(), horizontalProductsInAppItemBean.ʻᐝ()));
            this.ˏॱ.setVisibility(4);
        }
    }

    private void ˏ(long j, HorizontalProductsInAppItemBean horizontalProductsInAppItemBean) {
        if (this.ͺ != null) {
            this.ͺ.cancel();
        }
        this.ͺ = new d(100 + j, 1000, this.ˏॱ, this.ᐝ, this.ˊॱ, horizontalProductsInAppItemBean);
        this.ͺ.start();
    }

    private void ॱˊ() {
        cku ˏ = cku.ˏ(this.ʼॱ, cku.class, null, this.ʼॱ.getResources().getString(n.ʼᐨ));
        ˏ.ॱ(-1, this.ʼॱ.getResources().getString(n.ʼـ));
        ˏ.ˎ(-2, 8);
        ˏ.ॱ(new cks(this) {
            final /* synthetic */ HorizontalProductsInAppItemCard ˊ;

            {
                this.ˊ = r1;
            }

            public void enableNetworking() {
                this.ˊ.ˊॱ.setText(ContentManager.getInstant().getContext().getResources().getString(n.ʼᶥ));
                this.ˊ.ˊॱ.setEnabled(false);
            }

            public void upgrade() {
            }

            public void ˋ() {
            }
        });
        ˏ.ˋ(this.ʼॱ, this.ˋ.ॱ());
    }
}
